<?php

require "./lib/src/skey.php";

$uploads_url = base_url('uploads');
$admin_url = base_url('otakkanan');
$kirim_url = base_url('otakkiri');

$menu = $this->uri->segment(3, "lihat");
$mapdir = "<a href='$admin_url/' class='taut'>Home</a> &gt; ";

switch($menu)
{
	
	case "baru":
		$mapdir .= "
			<a href='$admin_url/acara' class='taut'>Acara</a>
			&gt; 
			<b>Acara Baru</b>
		";
		
		$isipage = "
					
				<div id='content2'>
						<h3>Tambah Acara Baru</h3>
						<div class='isicontent2'>
							 
							  <br />
							  <p>
								<b>Perhatian!</b> Acara adalah tanggung jawab setiap pengguna/user yang sedang aktif (login).
							  </p>
							  <br />
						</div>
						
							<div class='isicontent2'>
							
							  <form id='FrmMasukan' action='$kirim_url/acarabaru' method='post' onsubmit='return validasi_acara(this)'  enctype='multipart/form-data'  >
								
									<table>
										<tbody>
											<tr>
												<td class='left'>Nama *  </td>
												<td class='right'><input name='nama' type='text' placeholder='Acara' required /></td>
											</tr>
											<tr>
												<td class='left'>Deskripsi Acara *  </td>
												<td class='right'>
												<textarea name='deskripsi' id='deskripsi' placeholder='deskripsi' cols='30' rows='5' required>Deskripsi Acara</textarea>
												</td>
											</tr>
											<tr>
												<td class='left'>Lokasi Acara *  </td>
												<td class='right'><input name='lokasi' type='text' placeholder='Lokasi Acara' required /></td>
											</tr>
											<tr>
												<td class='left'>Tanggal Acara *  </td>
												<td class='right'><input name='tanggal' type='text' id='tglacara' required />
													<div class='note'>format : yyyy-mm-dd</div>
												</td>
											</tr>
											<tr>
												<td class='left'>Gambar  </td>
												<td class='right'><input name='gambar' type='file' />
												<br /><div class='keterangan'>Anda juga dapat menambahkan gambar untuk acara. </div></td>
											</tr>
											
											<tr>
												<td class='left'>&nbsp;</td>
												<td class='right'>Tanda Bintang (*) berarti Kolom wajib Diisi</td>
											</tr>
											<tr>
												<td class='left'> &nbsp; </td>
												<td class='right'>
												<input type='submit' value='Tambah'> &nbsp; <input type='reset' value='Ulang'></td>
											</tr>
										
										</tbody>
									</table>
									
							  </form>
							</div>
							
						</div>
			";
		
	;
	break;
	
	case "edit":
	
		$mapdir .= "
			<a href='$admin_url/acara' class='taut'>Acara</a>
			&gt; 
			<b>Edit Acara</b>
		";
		
		$ida = $this->input->get('ida');
		$hasil = $this->adminmodel->get_data_acara($ida);
		
		if($hasil !== FALSE)
		{
			foreach($hasil AS $hasil2)
			{
				$ida = $hasil2->idacara;
				$gambar = $hasil2->gambar;
				
				$tampil = "
							<tr>
								<td class='left'>Nama Acara * </td>
								<td class='right'><input name='nama' type='text' value='$hasil2->nama' /></td>
							</tr>
							<tr>
								<td class='left'>Deskripsi Acara * </td>
								<td class='right'><textarea name='deskripsi' id='deskripsi' cols='30' rows='5'>$hasil2->deskripsi</textarea></td>
							</tr>
							<tr>
								<td class='left'>Lokasi Acara * </td>
								<td class='right'><input name='lokasi' type='text' value='$hasil2->lokasi' /></td>
							</tr>
							<tr>
								<td class='left'>Tanggal Acara * </td>
								<td class='right'><input name='tanggal' type='text' id='tglacara' value='$hasil2->tanggal' />
									<div class='note'>format : yyyy-mm-dd</div>
								</td>
							</tr>
							<tr>
								<td class='left'>Gambar  </td>
								<td class='right'><input name='gambar' type='file' />
								<br /><div class='keterangan'>Anda juga dapat mengubah Gambar (kosongkan jika tidak akan diubah). </div></td>
							</tr>
						
							<tr>
								<td class='left'>&nbsp;</td>
								<td class='right'>Tanda Bintang (*) berarti Kolom wajib Diisi</td>
							</tr>
							<tr>
								<td class='left'> &nbsp; </td>
								<td class='right'><input type='hidden' name='ida' value='$ida' /><input type='hidden' name='oldgambar' value='$gambar' />
								<input type='submit' value='Ubah'> &nbsp; <input type='reset' value='Ulang'></td>
							</tr>";
			}
		}else{
			$tampil = "<tr>
							<td class='left'>&nbsp;</td>
							<td class='right'>Data Tidak Ditemukan</td>
						</tr>";
		}
		
		$isipage = "
				<div id='content2'>
						<h3>Edit Acara</h3>
							<div class='isicontent2'>
							
							  <form id='FrmMasukan' action='$kirim_url/updateacara' method='post' enctype='multipart/form-data' >
								
									<table>
										<tbody>
										
											$tampil
										
										</tbody>
									</table>
									
							  </form>
							</div>
							
						</div>
			";
	;
	break;
	
	
	
	case "detail":
		$mapdir .= "
			<a href='$admin_url/acara' class='taut'>Acara</a>
			&gt; 
			<b>Detail</b>
		";
		
		$ida = $this->input->get('ida');
		$hasil = $this->adminmodel->get_data_acara($ida);
		
		if($hasil !== FALSE)
		{
			foreach($hasil AS $hasil2)
			{
				$hariini = date("Y-m-d");
				$tgl = strtotime($hasil2->tanggal);
				$tanggal = date("Y-m-d", $tgl);
				$pelaksanaan = date("d-m-Y", $tgl);
				$jam = date("H.i",$tgl);
				$nama = html_escape($hasil2->nama);
				$deskripsi = auto_link(xss_clean($hasil2->deskripsi));
				$lokasi = html_escape($hasil2->lokasi);
				$gambar = "";
				$status = "";
				
				if( ! empty($hasil2->gambar))
				{
					$gambar = "<a id='lihat' href='$uploads_url/acara/$hasil2->gambar'><img alt='Gambar Acara' src='$uploads_url/acara/$hasil2->gambar' class='preview' /></a>";
				}
				
				if($tanggal < $hariini)
				{
					$status = "(<b>Telah Berakhir</b>)";
				}
				
				
				$tampil = "<tr>
								<td class='left'>Nama Acara </td>
								<td class='right'> 
									$nama $status 
									<a href='$admin_url/acara/edit?ida=$ida' class='taut'>Edit</a> &nbsp; 
									<a href='$kirim_url/hapusacara?ida=$ida' onclick='return konfirmhapus()' title='Hapus Acara'>Hapus</a>
								</td>
							</tr>
							
							<tr>
								<td class='left'>Waktu Pelaksanaan </td>
								<td class='right'>$pelaksanaan &nbsp; jam &nbsp; $jam</td>
							</tr>
							<tr>
								<td class='left'>Lokasi </td>
								<td class='right'>$lokasi</td>
							</tr>
							<tr>
								<td class='left'>Deskripsi Acara </td>
								<td class='right'>$deskripsi</td>
							</tr>
							<tr>
								<td class='left'>Gambar/Brosur </td>
								<td class='right'>$gambar</td>
							</tr>
							
							<tr>
								<td class='left'>&nbsp;</td>
								<td class='right'>&nbsp;</td>
							</tr>
							<tr>
								<td class='left'> &nbsp; </td>
								<td class='right'><a href='$admin_url/acara' class='taut'>&lt;&lt; Kembali</a></td>
							</tr>";
			}
		}else{
			$tampil = "<tr>
							<td class='left'>&nbsp;</td>
							<td class='right'>Data Tidak Ditemukan</td>
						</tr>";
		}
		
		$isipage = "
				<div id='content2'>
						<h3>Detail Acara</h3>
							<div class='isicontent2'>
							
								<table>
									<tbody>
									
										$tampil
									
									</tbody>
								</table>
									
							</div>
							
						</div>
			";
	;
	break;
	
	default:
	
		$mapdir .= "
			<b>Acara</b>
		";
		
		$awal = $this->input->get('awal');
		$acara = $this->adminmodel->get_acara($awal);
		$dataacara = "";
		$hariini = date("Y-m-d");
		
		if($acara !== FALSE)
		{
			foreach($acara AS $dacara)
			{
				
				$ida = $dacara->idacara;
				$nama = html_escape($dacara->nama);
				$status = "";
				$pelaksanaan = date("Y-m-d", strtotime($dacara->tanggal));
				
				if($pelaksanaan < $hariini)
				{
					$status = "(<b>Telah Terlewati</b>)";
				}
				
				if($dacara->uid != $uid)
				{
				$dataacara .= "
					<tr>
						<td class='left'>$nama $status</td>
						<td class='right'> 
							<a href='$admin_url/acara/detail?ida=$ida'>Detail</a> &nbsp; 
						</td>
					</tr>";
				}
				else{
					$dataacara .= "
					<tr>
						<td class='left'>$nama $status</td>
						<td class='right'> 
							<a href='$admin_url/acara/detail?ida=$ida'>Detail</a> &nbsp; 
							<a href='$admin_url/acara/edit?ida=$ida' class='taut'>Edit</a> &nbsp; 
							<a href='$kirim_url/hapusacara?ida=$ida' onclick='return konfirmhapus()' title='Hapus Acara'>Hapus</a>
						</td>
					</tr>";
				}
				
			}
		}else{
			$dataacara = "<tr><td class='left'>&nbsp;</td><td class='right'>Belum ada data Acara. <a href='$admin_url/acara/baru' class='taut'>Buat Acara?</a></td></tr>";
		}
		
		$config['base_url'] = $admin_url.'/acara?event=lihat';
		$config['total_rows'] = $this->adminmodel->hitung_data('idacara','dn_event');
		$config['per_page'] = 10; 
		$config['anchor_class'] = 'class="taut"';
		$config['page_query_string'] = TRUE;
		$config['query_string_segment'] = 'awal';

		$this->pagination->initialize($config); 
		$halaman = $this->pagination->create_links();
		
		$isipage = "
				<div id='content2'>
						<h3>Daftar Acara</h3>
							<div class='isicontent2'>
							 <table>
								<tbody>
									<tr><td class='left'><a href='$admin_url/acara/baru' class='taut'>Tambah Baru</a></td><td class='right'>&nbsp;</td></tr>
									<tr><td class='left'>&nbsp;</td><td class='right'>&nbsp;</td></tr>
									$dataacara
									<tr><td class='left'>&nbsp;</td><td class='right'>&nbsp;</td></tr>
									<tr><td class='left'><a href='$admin_url/acara/baru' class='taut'>Tambah Baru</a></td><td class='right'>$halaman</td></tr>
								</tbody>
							 </table>
							</div>
							
					</div>
			";
	;
	break;
}


$data['map_dir'] = $mapdir;
$data['isi_page'] = $isipage;
$data['site_title'] = 'Event - Dadan Network';
$data['base_url'] = base_url();
$data['tahun_sekarang'] = date("Y");

$this->parser->parse('template/admin', $data);


/* End of file acara.php */
/* Location: ./application/views/admin/acara.php */
